#include "ring.h"

ring* RingInit(ring* to,void* mark)
{
	to->forw = to;
	to->next = to;
	to->mark = mark;
	return to;
}

int RingInsert(ring* to,ring* sRing)
{
	if(CheckEmpty(sRing)) return 0;	
	sRing->forw = to;
	sRing->next = to->next;
	to->next->forw = sRing;
	to->next = sRing;
	return 1;
}

int RingCombine(ring* a,ring* b)
{
	if(CheckEmpty(a) || CheckEmpty(b)) return 0;
	c = a->next;
	d = b->next;
	a->next = d;
	c->forw = b;
	d->forw = a;
	b->next = c;
}

int RingRemove(ring* tRing)
{
	if(CheckEmpty(tRing)) return 0;	
	tRing->forw->next = tRing->next;
	tRing->next->forw = tRing->forw;
	tRing->forw = NULL;
	tRing->next = NULL;
	return 1;
}

int CheckEmpty(ring* tRing)
{
	if(tRing->forw == NULL || tRing->next == NULL)
	{
		return 1;
	}
return 0;
}

ring* RingForward(ring* tRing)
{
	return tRing->forw;
}
ring* RingNext(ring* tRing)
{
	return tRing->next;
}
